from .MouseListener import MouseListener


class MouseAreaListener(MouseListener):
    def __init__(self, callback=None):
        super(MouseAreaListener, self).__init__(callback)

    def callback(self, x, y, button, pressed):
        if pressed:
            self.pressX = int(x)
            self.pressY = int(y)
            self.pressButton = button
        else:
            x = int(x)
            y = int(y)
            startX = int(self.pressX)
            startY = int(self.pressY)
            width = int(abs(x - startX))
            height = int(abs(y - startY))
            self._callback(min(x, startX), startY, width, height, self.pressButton)
            for window in self._maskWindows:
                window.deleteLater()

            return False
